package com.qf.day13.work;

import java.util.*;

public class Demo2 {
    private static  HashMap<Integer, String> map = new HashMap<>();
    public static String whoWin(String year) {
        int i = Integer.parseInt(year);
        if (map.containsKey(i)) {
            return map.get(i);
        }
        return "没举办过世界杯";
    }
    public static List<Integer> winningYear(String country){
        List<Integer> arrayList = new ArrayList<>();

        map.forEach((k,v)->{
            if(v.equals(country)){
                arrayList.add(k);
            }
        });
        return arrayList;
    }
    public static void createMap(HashMap map) {
        map.put(2006,"意大利");
        map.put(2002,"巴西");
        map.put(1998,"法国");
        map.put(1994,"巴西");
        map.put(1990,"德国");
        map.put(1986,"阿根廷");
        map.put(1982,"意大利");
        map.put(1978,"阿根廷");
        map.put(1974,"德国");
        map.put(1970,"巴西");
        map.put(1966,"英格兰");
        map.put(1962,"巴西");
        map.put(1958,"巴西");
        map.put(1954,"德国");
        map.put(1950,"乌拉圭");
        map.put(1938,"意大利");
        map.put(1934,"意大利");
        map.put(1930,"乌拉圭");
    }
    public static void main(String[] args) {
        createMap(map);
        System.out.println("请输入年份");
        Scanner scanner = new Scanner(System.in);
        String year = scanner.next();
        System.out.println(whoWin(year));
        System.out.println("请输入国家");
        String country = scanner.next();
        List<Integer> list = winningYear(country);
        if(list.isEmpty()){
            System.out.println("该国没有获得过冠军");
        }
        list.forEach(e-> System.out.print(e+" "));
        System.out.println(" ");
        list.sort((o1, o2) -> o1-o2);
       list.forEach(e-> System.out.print(e+" "));
    }
}
